using System;
using System.IO;
using System.Xml;

namespace Altova.IO
{
	public class StreamOutput : Output
	{
		private Stream stream;

		private FileMode filemode = FileMode.Create;

		protected string filename;

		public override Stream Stream
		{
			get
			{
				if (stream == null)
				{
					stream = new FileStream(filename, filemode);
				}
				return stream;
			}
		}

		public override TextWriter Writer
		{
			get
			{
				throw new Exception("This is not a writer");
			}
		}

		public override XmlDocument Document
		{
			get
			{
				throw new Exception("This is not an XML Dom tree");
			}
		}

		public StreamOutput(Stream s)
			: base(OutputType.Stream)
		{
			stream = s;
		}

		public StreamOutput(string f, FileMode fm)
			: base(OutputType.Stream)
		{
			filename = f;
			filemode = fm;
		}

		public override void Close()
		{
			stream.Close();
		}
	}
}
